<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家设计师控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajudesignerController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete_deep',
			'input_change_ajax',
			'input_change_unique',
			'forbid',
			'closeitem',
			'openitem',
			'resume',
			'clear_recycle',
			'save_sort'
		);
		
		parent::init__();
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.jiajudesigner_position']=array('like',"%".Q::G('jiajudesigner_position')."%");
		$arrMap['A.jiajudesigner_style']=array('like',"%".Q::G('jiajudesigner_style')."%");
		$arrMap['A.jiajudesigner_telephone']=array('like',"%".Q::G('jiajudesigner_telephone')."%");
		$arrMap['A.jiajudesigner_qq']=array('like',"%".Q::G('jiajudesigner_qq')."%");
		$arrMap['A.jiajudesigner_school']=array('like',"%".Q::G('jiajudesigner_school')."%");
		$arrMap['A.jiajudesigner_name']=array('like',"%".Q::G('jiajudesigner_name')."%");
		$arrMap['A.jiajucompany_id']=$GLOBALS['_company_']['jiajucompany_id'];
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);

		$nJiajudesignerType=Q::G('jiajudesigner_type');
		if($nJiajudesignerType!==null && $nJiajudesignerType!=''){
			$arrMap['A.jiajudesigner_type']=$nJiajudesignerType;
		}
	}

	protected function AInsertObject_($oModel){
		// 商家&城市
		$oModel->jiajucompany_id=$GLOBALS['_company_']['jiajucompany_id'];
		$oModel->site_id=$GLOBALS['_company_']['site_id'];

		// 修改后提交
		if($oModel->jiajudesigner_status==1){
			$oModel->jiajudesigner_status=11;
		}
	}

	protected function AEditObject_($oModel){
		if(in_array($oModel->jiajudesigner_status,array(9,3)) || $oModel->jiajucompany_id!=$GLOBALS['_company_']['jiajucompany_id']){
			$this->E('你没有权限访问。');
		}
	}

	public function check_user(){
		$nUserid=trim(Q::G('user_id'));
		$nId=intval(Q::G('id'));

		if(!$nUserid){
			exit('true');
		}

		// 判断是否存在该帐号
		$oUser=UserModel::F('user_id=? AND user_status=1',$nUserid)->setColumns('user_id')->getOne();
		if(empty($oUser['user_id'])){
			exit('false');
		}

		// 查询条件
		$arrWhere=array();
		$arrWhere['user_id']=$nUserid;
		if($nId){
			$arrWhere['jiajudesigner_id']=array('neq',$nId);
		}

		$oJiajudesigner=JiajudesignerModel::F()->where($arrWhere)->setColumns('jiajudesigner_id')->getOne();
		if(empty($oJiajudesigner['jiajudesigner_id'])){
			exit('true');
		}else{
			exit('false');
		}
	}

}
